import { Controller } from '@nestjs/common';
import { GrpcMethod } from '@nestjs/microservices';

@Controller()
export class HeroController {
  @GrpcMethod('BookService')
  findBook(data: {id: number}, context: Record<string, any>){
    const items = [
      {id: 1, name: '前端调试通过秘籍', desc: '网页和node 调试0000'},
      {id: 2, name: 'nest 通过秘籍', desc: 'Nest 和各种后端中间件1111'}
    ];
    console.log(context)
    const result = items.find(item => item.id === data.id);
    if (!result) {
      return {
        id: data.id,
        name: '暂无',
        desc: '2323'
      }
    }

    return result;
  }

  @GrpcMethod('BookService', 'findOne')
  findOne2(){
    console.log('findOne');
    return {id: 13, name: 'findOne', desc: '新+ 微服务的 findOne方法'};
  }
}